#include <iostream>
#include <boost/asio.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <ctime>

class printer
{
  public:
    void print()
    {
        if (count_ < 5)
        {
            std::cout << std::clock() << " hello world! " << count_ << std::endl;
            ++count_;
            timer_.expires_at(timer_.expires_at() + boost::posix_time::seconds(1));
            timer_.async_wait(std::bind(&printer::print, this));
        }
    }

    printer(boost::asio::io_service &io) : timer_(io, boost::posix_time::seconds(1)), count_(0)
    {
        timer_.async_wait(std::bind(&printer::print, this));
    }
    ~printer()
    {
    }

  private:
    boost::asio::deadline_timer timer_;
    int                         count_;
};

int main(int argc, char const *argv[])
{
    boost::asio::io_service io;
    printer                 p(io);
    std::cout << std::clock() << std::endl;
    io.run();
    std::cout << std::clock() << std::endl;
    return 0;
}